In an existing data network, burstiness of message traffic may usually cause network congestion. A method for avoiding network congestion is implemented as follows: a rate of a message is limited at a receiver, and if the rate of the message is lower than a specified rate, the message is normally received; and if the rate of the message exceeds the specified rate, the message is dropped.
An existing method is to limit a rate of a message by virtue of a token bucket. A token bucket algorithm has standards RFC2687 and RFC2698, i.e. single-rate three-color dual-bucket and dual-rate three-color dual-bucket. FIG. 1 is a diagram of existing token-bucket-based rate limiting, in which when a message arrives, a system determines a time difference between the current message and a last message, then multiplies the time difference by an addition rate of tokens in a token bucket to obtain the number of filled tokens of the current token bucket, and finally adds the filled tokens and original tokens to obtain the number of tokens of the current token bucket until the current token bucket is full.
However, a rate of a message is usually higher than an addition rate of tokens during a practical application, so that a token bucket is in an “empty” state for a long time. Accordingly, tokens remaining in the token bucket generally enable short packets to pass only, while long packets are dropped. Therefore, rate limiting quality of long packets cannot be guaranteed.